package com.zzh.phone.scale.imagedisplay;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zzh.lib.views.image.ImageSource;
import com.zzh.lib.views.image.SubsamplingScaleImageView;
import com.zzh.phone.hviews.R.id;
import com.zzh.phone.hviews.R.layout;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public class ImageDisplayRotateFragment extends Fragment {

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(layout.imagedisplay_rotate_fragment, container, false);
        final SubsamplingScaleImageView imageView = rootView.findViewById(id.imageView);
        imageView.setImage(ImageSource.asset("swissroad.jpg"));
        imageView.setOrientation(90);
        final ImageDisplayActivity activity = (ImageDisplayActivity) getActivity();
        if (activity != null) {
            rootView.findViewById(id.previous).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.previous();
                }
            });
            rootView.findViewById(id.next).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.next();
                }
            });
        }
        rootView.findViewById(id.rotate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setOrientation((imageView.getOrientation() + 90) % 360);
            }
        });
        return rootView;
    }

}
